package com.sf.controller.cms;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.sf.kits.easyui.DataGridJson;
import com.sf.kits.time.TimeUtil;
import com.sf.model.cms.WebConfig;
import com.sf.util.StaticFactory;

import java.util.Date;
import java.util.List;

/**
 * 环境变量
 * Created by snowfigure on 2015/4/22.
 */

public class CmsWebConfigController extends Controller {
    public void index() {
        int type = getParaToInt("type",0);
        render("/WEB-INF/static/cms/WebConfig/system_config.ftl");
    }
    public void list(){
        int type = getParaToInt("type",0);

        int page = getParaToInt("page", 1);
        int rows = getParaToInt("rows", 10);
         Page<WebConfig> WebConfig_page = WebConfig.me.paginate(rows, page);

        List<WebConfig> list = WebConfig_page.getList();
        DataGridJson json = new DataGridJson();
        json.setRows(list);
        json.setTotal(WebConfig_page.getTotalRow()+"");
        renderJson(json);

    }
    public void edit(){
        keepModel(WebConfig.class);
        WebConfig webConfig = getModel(WebConfig.class);
        String updateTime = TimeUtil.format2(new Date());
        webConfig.set("update_time", updateTime);
        boolean flag = webConfig.update();
        StaticFactory.clearWebConfig();
        StaticFactory.setSystemConfigMap();
        renderText(flag + "");
    }
}
